import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * Author:  LiuTao
 * Version: 1.0
 * Date:    2023-10-11  20:43
 */
public class CardDemo {
    private String[] suits = {"♣️","♦️","♣️","♥️"};
    public List<Card> buyCard() {
        List<Card> cardList = new ArrayList<>();
        for(int i = 0; i < 4; i++) {
            for(int j = 1; j < 14; j++) {
                Card card = new Card(suits[i],j);
                cardList.add(card);
            }
        }
        return cardList;
    }

    public void shuffle(List<Card> cardList) {
        Random random = new Random();
        for(int i = cardList.size() - 1; i > 0; i--) {
            int index = random.nextInt(i);
            swap(cardList,i,index);
        }
    }

    public void swap(List<Card> cardList, int a, int b) {
        Card temp = cardList.get(a);
        cardList.set(a,cardList.get(b));
        cardList.set(b,temp);
    }

    public void getCard(List<Card> cardList) {
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();

        List<List<Card>> hands = new ArrayList<>();
        hands.add(hand1);
        hands.add(hand2);
        hands.add(hand3);

        for(int i = 0; i < 5; i++) {
            for(int j = 0; j < 3; j++) {
                Card card = cardList.remove(0);
                hands.get(j).add(card);
            }
        }

        System.out.println("第一个人的牌：");
        System.out.println(hand1);
        System.out.println("第二个人的牌：");
        System.out.println(hand2);
        System.out.println("第三个人的牌：");
        System.out.println(hand3);
    }
}
